package com.prj.ufdm.cloud.svr.gateway.config;

import javax.annotation.Resource;

import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.prj.ufdm.cloud.svr.gateway.constant.WebSecurityConstants;

@Configuration
public class InitParamConfig implements EnvironmentAware{
	
	@Resource
	private Environment env;
	
	@Override
	public void setEnvironment(Environment environment) {
		String extraAllowUrl = env.getProperty("auth.alllow.url");
		try {
			if(extraAllowUrl!=null && !extraAllowUrl.equals("")) {
				WebSecurityConstants.AUTH_ALLLOW_URL = WebSecurityConstants.AUTH_ALLLOW_URL + "," + extraAllowUrl;
			}
		}
		catch(Exception er) {
			
		}
		String tokenValidMinutes = env.getProperty("token.valid.minutes");
		try {
			if(tokenValidMinutes!=null && !tokenValidMinutes.equals("")) {
				WebSecurityConstants.TOKEN_VALID_MINUTES = Integer.parseInt(tokenValidMinutes);
			}
		}
		catch(Exception er) {
			
		}
		String redisStartUsing = env.getProperty("web.redis.enabled");
		try {
			if(redisStartUsing==null || "".equals(redisStartUsing) || redisStartUsing.equals("true")) {
				WebSecurityConstants.REDIS_ENABLED = true;
			}
			else {
				WebSecurityConstants.REDIS_ENABLED = false;
			}
		}
		catch(Exception er) {
			
		}
	}
}
